/**
 * 项目名：	Rumba Plan
 * 
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2006，所有权利保留。
 * 
 * 文件名：	ViewDomainAdvSys.java
 * 模块说明：	
 * 修改历史：
 * 2006-6-21 - lxm - 创建。
 */
package com.hd123.rumba.action.domain;

import net.sf.hibernate.HibernateException;

import com.hd123.rumba.action.organization.ViewOrganizationAdvSys;
import com.hd123.rumba.cartridge.FVRumbaAdvSys;
import com.hd123.rumba.domain.biz.IBDomainMgr;
import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.request.Action;
import com.hd123.rumba.request.ActionConstants;
import com.hd123.rumba.sql.biz.BSQLSubquery;

/**
 * 域 | Action | FVRumbaAdvSys
 * 
 * @author lxm
 * 
 */
public class ViewDomainAdvSys extends BaseViewDomain implements Action {

  public static final String CAPTION_VIEW = "域维护(高级)";

  /* 权限常量 */
  public static final String FUNCV_PREFIX = FVRumbaAdvSys.FUNCV_PREFIX;
  public static final String PERMISSION_VIEW = FUNCV_PREFIX + ".域.查看权";
  public static final String PERMISSION_FUNCVIEW_LOAD = FUNCV_PREFIX + ".域.构件包功能视图.装载权";
  public static final String PERMISSION_FUNCVIEW_UNLOAD = FUNCV_PREFIX + ".域.构件包功能视图.卸载权";
  public static final String PERMISSION_RECYCLE_VIEW = FUNCV_PREFIX + ".域.回收站.查看权";

  public String execute() throws Exception {
    String url = ActionConstants.NOTIMPLEMENTED;
    dd.put("viewName", "ViewDomainAdvSys");

    String startnode = (String) dd.getFormValue("start");
    if (startnode == null)
      startnode = "list";
    if ("list".equals(startnode)) {
      String isRecycleStr = (String) dd.getFormValue("isRecycle");
      if (isRecycleStr == null)
        isRecycleStr = "FALSE";
      Boolean isRecycle = "TRUE".equalsIgnoreCase(isRecycleStr) ? Boolean.TRUE : Boolean.FALSE;
      if (isRecycle.booleanValue())
        url = this.executeWithPermission("listRecycle", PERMISSION_RECYCLE_VIEW);
      else
        url = this.executeWithPermission("list", PERMISSION_VIEW);
    } else if ("filter".equals(startnode))
      url = this.executeWithPermission("filter", PERMISSION_VIEW);
    else if ("view".equals(startnode))
      url = this.executeWithPermission("view", PERMISSION_VIEW);
    else if ("viewOrganization".equals(startnode))
      url = this.executeWithPermission("viewOrganization", ViewOrganizationAdvSys.PERMISSION_VIEW);
    else if ("browse".equals(startnode))
      url = this.executeWithPermission("browse", null);
    else if ("loadFuncView".equals(startnode))
      url = this.executeWithPermission("loadFuncView", PERMISSION_FUNCVIEW_LOAD);
    else if ("unloadFuncView".equals(startnode))
      url = this.executeWithPermission("unloadFuncView", PERMISSION_FUNCVIEW_UNLOAD);

    return url;
  }

  protected void addForceFilter(BSQLSubquery bsq) {
    // Do Nothing
  }

  public String getPermission(String functionName, String domainUuid, Boolean isRecycle)
      throws BusinessException, HibernateException {
    return this.getPermission(functionName, IBDomainMgr.VALUE_RELATIONSHIP_OTHER, isRecycle);
  }

  public String getPermission(String functionName, int relationship, Boolean isRecycle)
      throws BusinessException, HibernateException {
    if (!isRecycle.booleanValue()) {
      if (ViewDomain.FUNCTION_VIEW.equals(functionName))
        return PERMISSION_VIEW;
      if (ViewDomain.FUNCTION_FUNCVIEW_LOAD.equals(functionName))
        return PERMISSION_FUNCVIEW_LOAD;
      if (ViewDomain.FUNCTION_FUNCVIEW_UNLOAD.equals(functionName))
        return PERMISSION_FUNCVIEW_UNLOAD;
    } else {
      if (ViewDomain.FUNCTION_VIEW.equals(functionName))
        return PERMISSION_RECYCLE_VIEW;
    }
    return null;
  }

  protected void putFormPermissions(Boolean isRecycle) throws BusinessException {
    if (isRecycle.booleanValue()) {
      dd.put("permissionView", PERMISSION_RECYCLE_VIEW);
      dd.put("permissionAnotherView", PERMISSION_VIEW);
    } else {
      dd.put("permissionView", PERMISSION_VIEW);
      dd.put("permissionAnotherView", PERMISSION_RECYCLE_VIEW);
    }
    dd.put("permissionFuncViewLoad", PERMISSION_FUNCVIEW_LOAD);
    dd.put("permissionFuncViewUnload", PERMISSION_FUNCVIEW_UNLOAD);
  }

}
